home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / CTFASMTT.ZIP / LESSON3.DOC < prev    next >
Text File  |  1994-10-30  |  5KB  |  131 lines

  1. LESSON3 - INTERRUPTS LABELS AND DB
  2.  
  3. know, if we want to, let say do a program thats just run, the struc
  4. I showed you before is not complete because, it will not exit,
  5. we must tell dos we want to exit, then how will we do it :
  6. simply by using the operator "int" which calls to interrupt
  7. (0..0FFH) and instruct him what to do, so lets detailt of some int's :
  8.  
  9. 009h - the keyboard interrupt
  10. 010h - the screen interrupt
  11. 013h - the sectors, (format, read, write) interrupt
  12. 016h - the keyboard interrupt
  13. 017h - the printer interrupt
  14. 021h - the main dos command
  15.  
  16. know each interrupt got many command and each one needs difrrent parameters
  17. (if you want to know get the complete int list from your local BBS)
  18.  
  19. INT 21 - TERMINATE
  20.  
  21. ah - 4ch
  22. al - errorlevel
  23.  
  24. so in order to initiate this interrupt we will do :
  25.  
  26. mov ah,4ch
  27. mov al,0        ; if you want it can every value
  28. int 21h         ; and then the program will exit to dos
  29.  
  30. but how will the compiler know where to start, well we have to tell
  31. him, the compiler will know to start excatly in the first, label -
  32. label is a name which you can jump to him, the label will be like :
  33. Name : - "start :", "now :", "rt :" all of those are labels, so this is
  34. a basic (working) assembly program :
  35.  
  36. Sseg segment  
  37.   db 10 dup (?)  ; will be disscused late
  38. ends          
  39.  
  40. Dseg segment
  41. ends
  42.  
  43. Cseg segment
  44. assume cs:cseg,ds:dseg,ss:sseg
  45.  
  46. start :              ; the compiler will start here
  47.  
  48.       mov ah,4ch
  49.       mov al,0
  50.       int 21h        ; terminate
  51. ends                 ; the segment must finish before the label
  52. end start            ; close the label
  53. end                  ; tell compiler script ends here
  54.  
  55. that was easy, it's the main assembly struc, but it can be much more complexed
  56. now in the sseg (stack) there was "db" now what is that, well if (most
  57. of the times) assembly registers are not enough so you (like pascal,c) can
  58. define variables, how ????
  59. well you have to operators - db,dw,dd,dt :
  60. DB - define byte, the var will be 1 byte (8 bit)
  61. DW - define word, the var will be 2 bytes (word, 16 bit)
  62. DD - define double, the var will be 4 bytes (double word,32 bit)
  63. DT - define ten, then var will be 10 bytes (not used)
  64.  
  65. the decleration goes like this :
  66. name type [number] value.
  67. examples : try db 1 - it will define "try" as 1 byte with starting value 1
  68.            tru dw 4 - it will define "tru" as 2 byte with starting value 4
  69.            ytu dw ? - it will define "ytu" as 2 byte with unknown starting
  70.                       value
  71. now lets say that you want to define an array (like pascal : a:array[1..10]of
  72.                                                like c      : int c[100])
  73. you do as follow : name type number dup(value).
  74. lets say : gvr db 10 dup(2) - it will define "gvr" as 10 byte which each one
  75.                               has value of 2.
  76. but what if I want to define a messege or multiple values then what ??
  77. then it should be like :
  78.  
  79. messege - mes db "this is a messege",10,13,"$"
  80.  
  81. now the numbers after the second """ are optional, it's needed only
  82. for some interrupt.
  83. multiple values (vectors, etc.) then :
  84.  
  85. vec db 23,54,76,34,234,14,23,123,245
  86.     db 124,34,245,23,52,34,52,43,13
  87.     db 213,213,123,123
  88.  
  89. the db can be dw,dd or dt, and you can do it for how much you want
  90. but you must not pass the 64k limit.
  91.  
  92. but what if you want to write a messege then ???
  93. you will search the int which do that :
  94.  
  95. int 21h - write string
  96.  
  97. ah - 9
  98. ds:dx points to string (in the end "$" for termination)
  99.  
  100. so how will we do it ???
  101.  
  102. Sseg segment  
  103.   db 10 dup (?)
  104. ends
  105.  
  106. Dseg segment
  107.   msg db "dr. encryption",10,13,"$" ; for termination
  108. ends
  109.  
  110. Cseg segment
  111. assume cs:cseg,ds:dseg,ss:sseg
  112.  
  113. start :              ; the compiler will start here
  114.  
  115.       mov dx,offset msg  ; ds is already pointing to dseg
  116.       mov ah,9
  117.       int 21h            ; whop there he is
  118.  
  119.       mov ah,4ch
  120.       mov al,0
  121.       int 21h        ; terminate
  122. ends                 ; the segment must finish before the label
  123. end start            ; close the label
  124. end                  ; tell compiler script ends here
  125.  
  126. now what offset is, well offset will return the offset of the argument
  127. so if you write : mov dx,offset msg then dx will be the offset of the msg
  128. (offset is 16bit and so is segment ,so "mov al,offset ..." will be wrong)
  129. the operator seg will return the segment of the argument, but if you change
  130. ds and not return his original value the system will hang.
  131. so then the stack comes to buisness.